﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Printing;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;

namespace WPFSample.PrintBannerSample
{
    class PrintBanner:Window
    {
        TextBox txtbox;

        public PrintBanner()
        {
            this.Title = "Print Banner";
            this.SizeToContent = SizeToContent.WidthAndHeight;

            StackPanel stack = new StackPanel();
            this.Content = stack;

            this.txtbox = new TextBox();
            this.txtbox.Width = 250;
            this.txtbox.FontFamily = new System.Windows.Media.FontFamily("宋体");
            this.txtbox.Margin = new Thickness(12);
            stack.Children.Add(this.txtbox);

            Button btn = new Button()
            {
                Content = "_Print...",
                Margin = new Thickness(12),
                HorizontalAlignment = HorizontalAlignment.Center
            };
            btn.Click += this.PrintOnClick;
            stack.Children.Add(btn);

            this.txtbox.Focus();
        }

        private void PrintOnClick(object sender, RoutedEventArgs e)
        {
            PrintDialog dlg = new PrintDialog();
            if (dlg.ShowDialog().GetValueOrDefault())
            {
                PrintTicket prntkt = dlg.PrintTicket;
                prntkt.PageOrientation = PageOrientation.Portrait;
                dlg.PrintTicket = prntkt;

                BannerDocumentPaginator paginator = new BannerDocumentPaginator();
                paginator.Text = this.txtbox.Text;
                paginator.PageSize = new Size(dlg.PrintableAreaWidth, dlg.PrintableAreaHeight);
                dlg.PrintDocument(paginator, "Banner: " + this.txtbox.Text);
            }
        }
    }
}
